package com.kuaifawu.lwnlawyerclient.Model;

import android.app.Activity;
import android.content.SharedPreferences;

import com.kuaifawu.lwnlawyerclient.Activity.MainActivity;

import java.net.URL;

/**
 * Created by zhangminglei on 15/1/15.
 */
public class LWNModel_user{

    private static LWNModel_user ourInstance = new LWNModel_user();

    public static LWNModel_user getInstance() {
        return ourInstance;
    }

    private LWNModel_user() {

    }

    public String getString_deviceToken(Activity activity_save){
        SharedPreferences userInfo = activity_save.getSharedPreferences("userInfo", 0);
        String token = userInfo.getString("deviceToken", null);
        return token;
    }

    public String getString_token(Activity activity_save){
        SharedPreferences userInfo = activity_save.getSharedPreferences("userInfo", 0);
        String token = userInfo.getString("token",null);
        return token;
    }

    public void setString_token(Activity activity_save,String token){
        SharedPreferences userInfo = activity_save.getSharedPreferences("userInfo", 0);
        SharedPreferences.Editor editor = userInfo.edit();
        editor.putString("token",token);
        editor.commit();
    }

    public String getString_uid(Activity activity_save){
        SharedPreferences userInfo = activity_save.getSharedPreferences("userInfo", 0);
        String uid = userInfo.getString("uid", null);
        return uid;
    }

    public void setString_deviceToken(Activity activity_save, String deviceToken){
        SharedPreferences userInfo = activity_save.getSharedPreferences("userInfo", 0);
        SharedPreferences.Editor editor = userInfo.edit();
        editor.putString("deviceToken", deviceToken);
        editor.commit();
    }

    public void setString_uid(Activity activity_save,String uid){
        SharedPreferences userInfo = activity_save.getSharedPreferences("userInfo", 0);
        SharedPreferences.Editor editor = userInfo.edit();
        editor.putString("uid", uid);
        editor.commit();
    }

    public String getString_userPhone(Activity activity_save){
        SharedPreferences userInfo = activity_save.getSharedPreferences("userInfo", 0);
        String phone = userInfo.getString("phone", null);
        return phone;
    }

    public void setString_userPhone(Activity activity_save,String phone) {
        SharedPreferences userInfo = activity_save.getSharedPreferences("userInfo", 0);
        SharedPreferences.Editor editor = userInfo.edit();
        editor.putString("phone", phone);
        editor.commit();
    }

    /**
     * 退出登录
     */
    public void loginOut(Activity activity_save){
        SharedPreferences userInfo = activity_save.getSharedPreferences("userInfo", 0);
        SharedPreferences.Editor editor = userInfo.edit();
        editor.clear().commit();
    }
}
